home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Source / 20-NetworkServices / dhcp / dhcp-config.frm.z / dhcp-config.frm
Encoding:
Text File  |  2002-06-12  |  6.5 KB  |  255 lines

  1. #!/usr/bin/perl5
  2. #
  3. # dhcp-config.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: dhcp-config.frm,v 1.29 1997/11/17 19:03:42 shotes Exp $
  21.  
  22. use Sys::Hostname;
  23. BEGIN { require "/usr/WebFace/lib/CGI.pm"; import CGI; }
  24. require "/usr/OnRamp/lib/OnRamp.pm";
  25. require "/usr/OnRamp/lib/java.pm";
  26.  
  27. $help_page = "dhcp-config-help.html";
  28.  
  29. $type = $ARGV[0];
  30. if ($type eq "add") { $message = "New subnet added."; }
  31. elsif ($type eq "edit") { $message = "Subnet edited."; }
  32.  
  33. $query = new CGI;
  34.  
  35. $def_config_dir = "/var/dhcp/config";
  36. $netcgi = "dhcp-netconf.cgi";
  37. $title = "DHCP Server Options";
  38.  
  39. $srv_off = system, "/etc/chkconfig", "proclaim_server";
  40. $inetd_cf = "/etc/inetd.conf";
  41. $use_propel = "No";
  42.  
  43. $js =
  44. "type = \"subnet\";
  45. $js_account_main
  46. $js_error_box
  47. $js_help
  48. $js_ip
  49. function testAdd(form) {
  50.     Ctrl = form.newIP;
  51.     if (Ctrl.value == \"\") {
  52.         errorBox (Ctrl, \"The subnet IP address is required.\");
  53.         return (false);
  54.     }
  55.     if (!testIPaddress(Ctrl.value,false)) {
  56.         errorBox (Ctrl, \"The subnet IP address is invalid.\");
  57.         return (false);
  58.     }
  59.     return (true);
  60. }";
  61.  
  62. open(OUT,"> $dummy"); close(OUT);
  63.  
  64. &getLeases;
  65.  
  66. if ($query->param) {
  67.     $subnet = $query->param('chosen');
  68.     $subnet =~ /([\d.]+)/;
  69.     $subnet = $1;
  70.  
  71.     if ($query->param('add')) {
  72.     $newIP = $query->param('newIP');
  73.     &error("Network address required.") if !$newIP;
  74.     &error("Invalid IP Address.") if &check_ipaddr($query->param('newIP'));
  75.     &addLease($query->param('newIP')); 
  76.     }
  77.     elsif ($query->param('doit')) { 
  78.     $delFile = $query->param('delFile');
  79.     if ($delFile && $delFile ne "Invalid") {    # Too late to check into  
  80.         &delete($delFile);                # quirky CGI.pm bug
  81.         &getLeases;
  82.         $message .= "  Subnet deleted.";
  83.     } else { $message = "No changes made."; }
  84.     }
  85.     elsif ($query->param('edit')) {
  86.     &error("To edit an existing subnet, first select a subnet from the
  87.         list, then click the edit button.") if !$subnet; 
  88.     &edit($subnet); 
  89.     }
  90.     elsif ($query->param('delete')) {
  91.     &error("To delete an existing subnet, first select a subnet from the
  92.         list, then click the delete button.") if !$subnet; 
  93.     print $query->header;
  94.     &js_title_block($title,$js);
  95.     $message = qq|Click "Ok" to save changes.|;
  96.     &generic($subnet); 
  97.     exit 0;
  98.     } elsif (!$type) { $message = "Use buttons to submit form."; }
  99. }
  100.  
  101. print $query->header;
  102.  
  103. $help = $document_root . $ENV{"SCRIPT_NAME"};
  104. $help =~ s/cgi$/hlp/;
  105. exec $help if ($query->param('help') eq "Help");
  106.  
  107. &js_title_block($title,$js);
  108.  
  109. if ($srv_off == 0) { &getFile; }    # chkconfig proclaim_server is on
  110.  
  111. if ($srv_on && $osf) { &getOptions; }
  112.  
  113. &generic;
  114.  
  115. sub error {
  116.     print $query->header;
  117.     &js_title_block($title,$js);
  118.     &error_block($_[0]);
  119.     &generic;
  120.     exit 0;
  121. }    
  122.  
  123. sub addLease {
  124.     $file = $netcgi . "?add$_[0]";
  125.     redirect($file);
  126.     exit(0);
  127. }    
  128.    
  129. sub delete {
  130.     $file = $def_config_dir . "/config." . $_[0];
  131.     unlink $file;
  132. }
  133.  
  134. sub edit {
  135.     $file = $netcgi . "?edit$_[0]";
  136.     redirect($file);
  137.     exit(0);
  138. }
  139.  
  140. sub getFile {
  141.     open(INETD, $inetd_cf) || die "Cannot open $inetd_cf";
  142.     while (<INETD>) {
  143.     if (/^#/) {
  144.         next;
  145.     }
  146.     # bootp dgram udp wait root /usr/etc/dhcp_bootp dhcp_bootp -o <file>
  147.     if (/^bootp/) {
  148.         chop;
  149.         @entlist = split(/\s+/);
  150.         if ($entlist[7] eq "-o") {
  151.         $osf = $entlist[8];
  152.         last;    # Break out of the while loop
  153.         }
  154.     }
  155.     }
  156.     close(INETD);
  157. }
  158.  
  159. sub getOptions {
  160.     $found = 0;
  161.     open(OPTIONS, $osf) || die "Cannot open $osf";
  162.     while(<OPTIONS>) {
  163.     if (/^#/) {
  164.         next;
  165.     }
  166.     chop;
  167.     @optlist = split(/\s+/);
  168.     $i = 0;
  169.     while ($optlist[$i]) {
  170.         if ($optlist[$i] eq "-c") {
  171.         $def_config_dir = $optlist[$i+1];
  172.         $found = 1;
  173.         last;
  174.         }
  175.         $i += 1;
  176.     }
  177.     if ($found == 1) {
  178.         last;
  179.     }
  180.     }
  181.     close(OPTIONS);
  182. }
  183.  
  184. sub getLeases {
  185.     undef @lst;
  186.     opendir(CONFIG, $def_config_dir) || 
  187.         &error("Unable to open directory $def_config_dir");
  188.     while ($name = readdir(CONFIG) ) {
  189.     if ($name =~ /^config\./) {
  190.         $ipa = $name;
  191.         $ipa =~ s/^config\.//;
  192.         if ($ipa ne "Default") { push(@lst,$ipa); }
  193.     }
  194.     }
  195.     closedir(CONFIG);
  196. }
  197.  
  198. sub generic {
  199.     &header_block($title);
  200.  
  201.     print "<i>$message</i>";
  202.  
  203.     print $query->startform("POST", "", "", "NAME=AccountForm", "onSubmit=\"return runSubmit()\"");
  204.  
  205.     if ($_[0]) { print "<input type=hidden name=delFile value=$_[0]>"; }
  206.  
  207.     print "<center><table width=400>";
  208.     print "<tr><th align=left>",$query->submit('add','Add New Subnet',
  209.     'onClick="markAdd()"'),"</th>";
  210.     print "<td>",$query->textfield(-name=>'newIP', -size=>19),"</td></tr>";
  211.  
  212.     if ($_[0]) { 
  213.     undef @locList;
  214.     foreach $arg (@lst) {
  215.         if ($arg ne $_[0]) { push(@locList,$arg); }
  216.     }
  217.     } else { @locList = @lst; }
  218.     print "<tr><th align=left>",$query->submit('edit','Edit Existing Subnet',
  219.     'onClick="markEdit()"'),"</th>";
  220.     print "<td rowspan=2>",&choice_list(*locList,'chosen',20),"</td></tr>";
  221.  
  222.     print "<tr><th align=left>",$query->submit('delete','Delete Existing Subnet','onClick="markDelete()"'),"</th></tr>";
  223.  
  224.     print "</table><br>";
  225.  
  226.     print &js_buttons('doit','Ok','onClick="markOther()"',
  227.         'onClick="markOther()"',
  228.         "onClick=\"do_help('$help_page'); return (false)\"");
  229.  
  230.     print $query->endform;
  231. }
  232.  
  233. sub old {
  234.     if ($#lst > -1) {
  235.  
  236.     print "<center><table width=300>";
  237.  
  238.     print "<tr><th align=left>Name</th><th>Edit</th><th>Delete</th></tr>";
  239.  
  240.     foreach $arg (@lst) {
  241.         print "<tr><td>",$arg,"</td><td align=center>",$query->submit("edt".$arg,"Edit"),
  242.         "</td><td align=center>",
  243.         "<input type=checkbox name=del$arg value='Delete'>",
  244.         "</td></tr>";
  245.     }
  246.     } else { print "<i><center>No clients currently configured.
  247.                     </center></i>"; }
  248.  
  249.     print "</table></center><br>";
  250.  
  251.     &button_table($query,'doit','Ok','help','Help');
  252.  
  253.     print $query->endform;
  254. }    
  255.